<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client\Credentials\Providers;

class CredentialsProvider
{
    private static $customChains;
    public static function chain()
    {
        $providers = func_get_args();
        if(empty($providers)) {
            throw new \AlibabaCloud\Client\Exception\ClientException("No providers in chain", \AlibabaCloud\Client\SDK::INVALID_ARGUMENT);
        }
        foreach ($providers as $provider) {
            if(!$provider instanceof \Closure) {
                throw new \AlibabaCloud\Client\Exception\ClientException("Providers must all be Closures", \AlibabaCloud\Client\SDK::INVALID_ARGUMENT);
            }
        }
        self::$customChains = $providers;
    }
    public static function flush()
    {
        self::$customChains = [];
    }
    public static function hasCustomChain()
    {
        return (bool) self::$customChains;
    }
    public static function customProvider($clientName)
    {
        foreach (self::$customChains as $provider) {
            $provider();
            if(\AlibabaCloud\Client\AlibabaCloud::has($clientName)) {
            }
        }
    }
    public static function defaultProvider($clientName)
    {
        $providers = [self::env(), self::ini(), self::instance()];
        foreach ($providers as $provider) {
            $provider();
            if(\AlibabaCloud\Client\AlibabaCloud::has($clientName)) {
            }
        }
    }
    public static function env()
    {
        return function () {
            $accessKeyId = AlibabaCloud\Client\envNotEmpty("ALIBABA_CLOUD_ACCESS_KEY_ID");
            $accessKeySecret = AlibabaCloud\Client\envNotEmpty("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
            if($accessKeyId && $accessKeySecret) {
                \AlibabaCloud\Client\AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)->asDefaultClient();
            }
        };
    }
    public static function ini()
    {
        return function () {
            $ini = AlibabaCloud\Client\envNotEmpty("ALIBABA_CLOUD_CREDENTIALS_FILE");
            if($ini) {
                \AlibabaCloud\Client\AlibabaCloud::load($ini);
            } else {
                \AlibabaCloud\Client\AlibabaCloud::load();
            }
            self::compatibleWithGlobal();
        };
    }
    private static function compatibleWithGlobal()
    {
        if(\AlibabaCloud\Client\AlibabaCloud::has("global") && !\AlibabaCloud\Client\AlibabaCloud::has(self::getDefaultName())) {
            \AlibabaCloud\Client\AlibabaCloud::get("global")->name(self::getDefaultName());
        }
    }
    public static function getDefaultName()
    {
        $name = AlibabaCloud\Client\envNotEmpty("ALIBABA_CLOUD_PROFILE");
        if($name) {
            return $name;
        }
        return "default";
    }
    public static function instance()
    {
        return function () {
            $instance = AlibabaCloud\Client\envNotEmpty("ALIBABA_CLOUD_ECS_METADATA");
            if($instance) {
                \AlibabaCloud\Client\AlibabaCloud::ecsRamRoleClient($instance)->asDefaultClient();
            }
        };
    }
}

?>